<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加物资</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>

<body>
<div class="weadmin-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="oid" class="layui-form-label">
                <span class="we-red">*</span>社团ID
            </label>
            <div class="layui-input-inline">
                <select id="oid" name="oid">
                    <option>请选择社团</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="we-red">*</span>物资名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="nums" class="layui-form-label">
                <span class="we-red">*</span>物资数量
            </label>
            <div class="layui-input-inline">
                <input type="text" id="nums" name="nums" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                <span class="we-red">*</span>物资价格
            </label>
            <div class="layui-input-inline">
                <input type="text" id="price" name="price" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tips" class="layui-form-label">
                <span class="we-red">*</span>物资简介
            </label>
            <div class="layui-input-inline">
                <textarea id="tips" name="tips" required="" lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="tips" class="layui-form-label"></label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
        </div>
    </form>
</div>
<script src="../../lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.extend({
        admin: '{/}../../static/js/admin'
    });
    layui.use(['form','layer','admin','jquery'], function(){
        var form = layui.form,
            admin = layui.admin,
            layer = layui.layer;
        var $ = layui.jquery;
        //form.render();
        //动态Select菜单

            $.ajax({
                type: "get",
                url: '/api/organ/queryOrganList',
                contentType:'application/json;charset=UTF-8',
                success: function(res) {
                    var data = res.data;
                    if(res.code == 0) {
                        $.each(data, function(index,item) {
                            $('#oid').append('<option value="'+item.id+'">'+item.name+'</option>');
                        });
                        form.render();
                    }
                }
            });

        //自定义验证规则
        form.verify({
            nums: function(e) {
                if (!e || isNaN(e)) return "只能填写数字"
            },
            price: function(e) {
                if (!e || isNaN(e)) return "只能填写数字"
            }
        });

        //监听提交
        form.on('submit(add)', function(data){
            console.log(data);
            var f = data.field;
            var d = {
                "oid":f.oid,
                    "name":f.name,
                    "nums":f.nums,
                     "price":f.price,
                    "tips":f.tips,
            };
            $.ajax({
                type: "post",
                url: '/api/organ/goods/insertGoods',
                contentType:'application/json;charset=UTF-8',
                data:JSON.stringify(d),
                success: function(res) {
                    if(res.code == 0) {
                        layer.msg("添加成功");
                    }
                }
            });
            return false;
        });


    });
</script>
</body>

</html>